/*
Borealis Library
A library of commonly used hydrological modeling building blocks

Copyright (C) 2008  Chris Marsh

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include "Observations_UnitTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION( ObservationTest );



void ObservationTest::setUp()
{

}

void ObservationTest::tearDown()
{

}

void ObservationTest::TestOpenFile()
{
	Borealis::Observation obs;
	obs.OpenFile("Observations.obs");

}

void ObservationTest::TestToFile()
{
	Borealis::Observation obs;
	obs.OpenFile("ObservationsTest2.met");
	obs.ToFile("obs_out.txt");

}

void ObservationTest::TestIterators()
{
	Borealis::Observation obs;
	obs.OpenFile("Observations.obs");

	Borealis::Observation::const_iterator itr;

	for(itr=obs.Begin();itr != obs.End(); itr++)
	{	
		std::cout << std::endl << (*itr).ToString() << std::endl;		
	}

	itr=obs.Begin();


	CPPUNIT_ASSERT((*itr).Get<std::string>("Date") == "2008-Feb-23 23:59:59");
	CPPUNIT_ASSERT((*itr).Get<float>("RH")		   ==  (float)0.2 );
	CPPUNIT_ASSERT((*itr).Get<float>("pRecip")	   ==  (float)5.0);

	itr++;

	CPPUNIT_ASSERT((*itr).Get<std::string>("Date") == "2008-Feb-24 23:59:59");
	CPPUNIT_ASSERT((*itr).Get<float>("RH")		   ==  (float)0.5 );
	CPPUNIT_ASSERT((*itr).Get<float>("pRecip")	   ==  (float)0.9);

	itr++;

	CPPUNIT_ASSERT((*itr).Get<std::string>("Date") == "2008-Feb-26 23:59:59");
	CPPUNIT_ASSERT((*itr).Get<float>("RH")		   == (float)0.8 );
	CPPUNIT_ASSERT((*itr).Get<float>("pRecip")	   == (float)5.55);

	Borealis::Observation::const_iterator itr2 = itr;
	itr2--;

	CPPUNIT_ASSERT((*itr2).Get<std::string>("Date") == "2008-Feb-24 23:59:59");
	CPPUNIT_ASSERT((*itr2).Get<float>("RH")		   ==  (float)0.5 );
	CPPUNIT_ASSERT((*itr2).Get<float>("pRecip")	   ==  (float)0.9);

	CPPUNIT_ASSERT((*itr).Get<std::string>("Date") == "2008-Feb-26 23:59:59");
	CPPUNIT_ASSERT((*itr).Get<float>("RH")		   ==  (float)0.8 );
	CPPUNIT_ASSERT((*itr).Get<float>("pRecip")	   ==  (float)5.55);

	Borealis::Observation::const_iterator itr3(itr2);

	itr3--;
	CPPUNIT_ASSERT((*itr3).Get<std::string>("Date") == "2008-Feb-23 23:59:59");
	CPPUNIT_ASSERT((*itr3).Get<float>("RH")		   ==  (float)0.2 );
	CPPUNIT_ASSERT((*itr3).Get<float>("pRecip")	   ==  (float)5.0);



}